home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EMSIF230.ARJ / EMSTEST.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  62KB  |  1,528 lines

  1. /***************************************************************************
  2. *   emstest.c                                                              *
  3. *   MODULE:  EMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.1                                                           *
  6. *   DATE:    12/01/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires emsif.h, testutil.h, and emstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.00A.                  *
  12. *                                                                          *
  13. *   Regression test and example for EMSIF.                                 *
  14. *                                                                          *
  15. *   This is part one of the regression tester and example for EMSIF.       *
  16. *   The other parts are named EMSTEST2.C and EMSTEST3.C. All three parts   *
  17. *   must be compiled and linked together along with the appropriate EMSIF  *
  18. *   library and a utilities file TESTUTIL.C to produce the tester          *
  19. *   executable. This program compiles under tiny, small, medium, compact,  *
  20. *   large, and huge models. Note that it doesn't quite fit into tiny       *
  21. *   model; the tiny model tester is actually three executables. When       *
  22. *   compiling for tiny model, one of the symbols TINYPASS1, TINYPASS2, or  *
  23. *   TINYPASS3 must be defined. See the example makefiles for further       *
  24. *   details on what needs to be linked with what to produce the tiny-model *
  25. *   executables.                                                           *
  26. *                                                                          *
  27. *   To use this tester: just run it. It requires no arguments and produces *
  28. *   output on stdout. It performs nearly 200 tests and parts of it run     *
  29. *   quite fast, even on an original IBM PC/XT (4.77 MHz). If you want to   *
  30. *   actually read the output, you should redirect the output to a file.    *
  31. *   If you just want to see whether the tests all pass, simply run it --   *
  32. *   if a test fails, execution aborts immediately.                         *
  33. *                                                                          *
  34. *   Certain types of failure may cause EMSTEST to not deallocate EMS or    *
  35. *   conventional memory that it has allocated. This should only occur if   *
  36. *   the library itself is malfunctioning (which should never happen to     *
  37. *   you, only to me!) or if you are trying a different compiler or         *
  38. *   unsupported memory model and the compiler and library are therefore    *
  39. *   not communicating properly. It may also happen if you press control-   *
  40. *   break.                                                                 *
  41. *                                                                          *
  42. *   Turbo C and older versions of Turbo C++ do not have the _fmemcmp() and *
  43. *   _fmemset() functions; I don't know about older versions of MSC. If     *
  44. *   your compiler does not have these functions, define the symbol         *
  45. *   NO_FFUNC and functions in the ancillary file TESTUTIL.C will be used   *
  46. *   instead.                                                               *
  47. *                                                                          *
  48. ***************************************************************************/
  49.  
  50. /*
  51. ** system includes <>
  52. */
  53.  
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57.  
  58.  
  59. /*
  60. ** custom includes ""
  61. */
  62.  
  63. #include "testutil.h"
  64.  
  65. #include "emsif.h"
  66. #include "emstest.h"
  67.  
  68.  
  69. /*
  70. ** local #defines
  71. */
  72.  
  73. /*
  74. ** misc: copyright strings, version macros, etc.
  75. */
  76.  
  77. /*
  78. ** typedefs
  79. */
  80.  
  81. /*
  82. ** global variables
  83. */
  84.  
  85. int testno = 1;                     /* number of test currently being done  */
  86. unsigned char far *frameptr[4];     /* pointers to EMS frames               */
  87. char *gblmsg = "";                  /* msg to be printed in test header     */
  88.  
  89.  
  90. /*
  91. ** static globals
  92. */
  93.  
  94. /*
  95. ** function prototypes
  96. */
  97.  
  98. /*
  99. ** functions
  100. */
  101.  
  102.  
  103. /***************************************************************************
  104. *   FUNCTION: MAIN                                                         *
  105. *                                                                          *
  106. *   DESCRIPTION:                                                           *
  107. *                                                                          *
  108. *       The master function.                                               *
  109. *                                                                          *
  110. *   ENTRY:                                                                 *
  111. *                                                                          *
  112. *       None.                                                              *
  113. *                                                                          *
  114. *   EXIT:                                                                  *
  115. *                                                                          *
  116. *       Void.                                                              *
  117. *                                                                          *
  118. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  119. *                                                                          *
  120. ***************************************************************************/
  121. main()
  122. {
  123.     int status;                     /* return status from library functions */
  124.  
  125.     /*
  126.     ** check initialization test
  127.     */
  128.     TESTHEADER();
  129.     printf("Making a call to EMMgetversion() before calling EMMlibinit().\n");
  130.     printf("The call should fail.\n");
  131.     EMMgetversion();
  132.     nofailcheck("EMMgetversion()", (int) _EMMerror, NULL, 0, 0);
  133.     weirdcodechk("EMMgetversion()", EMM_NOINIT, NULL, 0, 0);
  134.     TESTTAILER();
  135.  
  136.  
  137.     /*
  138.     ** initialize EMSIF
  139.     */
  140.     TESTHEADER();
  141.     printf("Calling EMMlibinit().\n");
  142.     printf("Should succeed if and only if Expanded Memory Manager for EMS version 3.0 or\n");
  143.     printf(" greater is present.\n");
  144.     status = EMMlibinit();
  145.     switch (status)
  146.     {
  147.         case EMMOOPS:
  148.             printf("EMMlibinit() failed, code 0x%X.\n",
  149.                                                     (unsigned int) _EMMerror);
  150.             exit(3);
  151.             break;
  152.  
  153.         case NOEMM:
  154.             printf("EMMlibinit() did not find an Expanded Memory Manager.\n");
  155.             exit(3);
  156.             break;
  157.  
  158.         case 0:
  159.             printf("EMMlibinit() returned OK.\n");
  160.             weirdcodechk("EMMlibinit()", 0, NULL, 0, 0);
  161.             break;
  162.  
  163.         default:
  164.             printf("EMMlibinit() returned strange value %d.\n", status);
  165.             exit(3);
  166.             break;
  167.     }
  168.     TESTTAILER();
  169.  
  170. /*
  171. ** The following section of code is included only in the first tiny-model
  172. ** executable and in non-tiny-model executables.
  173. */
  174. #ifndef TINYPASS2
  175. #ifndef TINYPASS3
  176.  
  177.     /*
  178.     ** test version call
  179.     */
  180.     TESTHEADER();
  181.     printf("Testing EMMgetversion().\n");
  182.     printf("Results should match value in _EMMversion.\n");
  183.     status = EMMgetversion();
  184.     weirdcodechk("EMMgetversion()", 0, NULL, 0, 0);
  185.     if (status != (int) _EMMversion)
  186.     {
  187.         printf("EMMgetversion() [0x%X] and _EMMversion [0x%X] differ.\n",
  188.                                            status, (unsigned int) _EMMversion);
  189.         exit(3);
  190.     }
  191.     printf("EMS version %d.%d.\n", ((status >> 4) & 0xF), (status & 0xF));
  192.     TESTTAILER();
  193.  
  194.  
  195.     /*
  196.     ** test allocation functions
  197.     */
  198.     do_alloc_tests(1L);
  199.     do_alloc_tests(16384L);
  200.     do_alloc_tests(55555L);
  201.     do_alloc_tests(0L);
  202.  
  203.     do_palloc_tests(1);
  204.     do_palloc_tests(5);
  205.  
  206. #endif
  207. #endif
  208.  
  209.     /*
  210.     ** test frame functions -- included in all executables
  211.     */
  212.     do_frame_tests();
  213.  
  214. /*
  215. ** The following section of code is included only in the first tiny-model
  216. ** executable and in non-tiny-model executables.
  217. */
  218. #ifndef TINYPASS2
  219. #ifndef TINYPASS3
  220.  
  221.     /*
  222.     ** test name functions
  223.     */
  224.     do_name_tests();
  225.  
  226.     /*
  227.     ** do mapping tests
  228.     */
  229.     do_map_tests();
  230.  
  231.     /*
  232.     ** test the save/restore facility
  233.     */
  234.     do_sr_tests();
  235.  
  236. #endif
  237. #endif
  238.  
  239. /*
  240. ** The following section of code is included only in the second tiny-model
  241. ** executable and in non-tiny-model executables.
  242. */
  243. #ifndef TINYPASS1
  244. #ifndef TINYPASS3
  245.  
  246.     /*
  247.     ** test copies of <= one page, frame caching on
  248.     */
  249.     gblmsg = "  SHORT COPY TESTS";
  250.     do_shortcopy_tests();
  251.     gblmsg = "";
  252.  
  253.     /*
  254.     ** test frame cache control
  255.     */
  256.     TESTHEADER();
  257.     printf("Testing frame caching enable/disable.\n");
  258.     if (_EMMframecache == 0)
  259.     {
  260.         printf("Frame caching is supposed to be on by default, seems to ");
  261.         printf("be off.\n");
  262.         exit(3);
  263.     }
  264.     _EMMdisc();
  265.     weirdcodechk("_EMMdisc()", 0, NULL, 0, 0);
  266.     if (_EMMframecache != 0)
  267.     {
  268.         printf("_EMMdisc() did not disable frame caching.\n");
  269.         exit(3);
  270.     }
  271.     _EMMenc();
  272.     weirdcodechk("_EMMenc()", 0, NULL, 0, 0);
  273.     if (_EMMframecache == 0)
  274.     {
  275.         printf("_EMMenc() did not enable frame caching.\n");
  276.         exit(3);
  277.     }
  278.     printf("Flag and function calls correspond OK.\n");
  279.     TESTTAILER();
  280.  
  281.     /*
  282.     ** test copies of <= one page, frame caching off
  283.     */
  284.     _EMMdisc();
  285.     gblmsg = "  SHORT COPY TESTS WITH FRAME CACHING OFF";
  286.     do_shortcopy_tests();
  287.     _EMMenc();
  288.  
  289. #endif
  290.  
  291. /*
  292. ** The following section of code is included only in the third tiny-model
  293. ** executable and in non-tiny-model executables.
  294. */
  295. #ifndef TINYPASS2
  296.  
  297.     /*
  298.     ** test copies of > 1 page, frame caching on
  299.     */
  300.     _EMMenc();
  301.     gblmsg = "  LONG COPY TESTS";
  302.     do_longcopy_tests();
  303.  
  304.     /*
  305.     ** test copies of > 1 page, frame caching off
  306.     */
  307.     _EMMdisc();
  308.     gblmsg = "  LONG COPY TESTS WITH FRAME CACHING OFF";
  309.     do_longcopy_tests();
  310.     gblmsg = "";
  311.     _EMMenc();
  312.  
  313. #endif
  314. #endif
  315.  
  316.     /* end and cleanup */
  317.     printf(">>>END\n");
  318.     printf("All tests succeeded.\n");
  319.  
  320.     exit(0);
  321. } /* end of main() */
  322.  
  323.  
  324. /***************************************************************************
  325. *   FUNCTION: DO_FRAME_TESTS                                               *
  326. *                                                                          *
  327. *   DESCRIPTION:                                                           *
  328. *                                                                          *
  329. *       This function tests EMSIF calls EMMgetnumframe(),                  *
  330. *       EMMgetframeaddr(), and EMMgetsinfraddr().                          *
  331. *                                                                          *
  332. *   ENTRY:                                                                 *
  333. *                                                                          *
  334. *       Void.                                                              *
  335. *                                                                          *
  336. *   EXIT:                                                                  *
  337. *                                                                          *
  338. *       Void.                                                              *
  339. *                                                                          *
  340. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  341. *                                                                          *
  342. *       Fills in the frameptr[] global array.                              *
  343. *                                                                          *
  344. ***************************************************************************/
  345. void do_frame_tests(void)
  346. {
  347.     frameinfo *framebuf;
  348.     int frames;
  349.     int status;
  350.     int loop;
  351.     unsigned int segaddr;
  352.  
  353.     /* set header */
  354.     gblmsg = "  FRAME TESTS";
  355.  
  356.     /* get number of frames */
  357.     TESTHEADER();
  358.     printf("Getting number of frames with EMMgetnumframe().\n");
  359.     if (_EMMversion < 0x40)
  360.     {
  361.         printf("Should be exactly 4.\n");
  362.     }
  363.     else
  364.     {
  365.         printf("Should be 4 or more.\n");
  366.     }
  367.     frames = EMMgetnumframe();
  368.     weirdcodechk("EMMgetnumframe()", 0, NULL, 0, 0);
  369.     if (frames < 4)
  370.     {
  371.         printf("EMMgetnumframe() returned OK but indicates only %d frames.\n",
  372.                                                                        frames);
  373.         exit(3);
  374.     }
  375.     if ((_EMMversion < 0x40) && (frames != 4))
  376.     {
  377.         printf("EMMgetnumframe() returned OK but indicates wrong number of\n");
  378.         printf("   frames (%d) for this version.\n", frames);
  379.         exit(3);
  380.     }
  381.     printf("EMMgetnumframe() returned OK, %d frames.\n", frames);
  382.     TESTTAILER();
  383.  
  384.     /* allocate memory for frame address buffer */
  385.     framebuf = (frameinfo *) calloc(frames, sizeof(frameinfo));
  386.     if (framebuf == (frameinfo *) NULL)
  387.     {
  388.         printf("OOPS! Couldn't allocate a buffer. Aborting.\n");
  389.         exit(3);
  390.     }
  391.  
  392.     /* get frame segment addresses */
  393.     TESTHEADER();
  394.     printf("Getting frame address info with EMMgetframeaddr().\n");
  395.     printf("Should succeed.\n");
  396.     status = EMMgetframeaddr(framebuf);
  397.     TRIPLECHECK("EMMgetframeaddr()", status, 0, framebuf, 0, 0);
  398.     printf("EMMgetframeaddr() returned OK, checking info returned...\n");
  399.     for (loop = 0; loop < frames; loop++)
  400.     {
  401.         /* check for valid frame number */
  402.         if (framebuf[loop].frameno >= frames)
  403.         {
  404.             printf("Frame number in slot %d is bad (%u).\n", loop,
  405.                                                        framebuf[loop].frameno);
  406.             free(framebuf);
  407.             exit(3);
  408.         }
  409.         /* check that frame segment address is on a page (16K) boundary */
  410.         if ((framebuf[loop].segaddr & 0x3FF) != 0)
  411.         {
  412.             printf(
  413.              "Frame segment %u, slot %d, frame number %u, not page aligned.\n",
  414.              framebuf[loop].segaddr, loop, framebuf[loop].frameno);
  415.             free(framebuf);
  416.             exit(3);
  417.         }
  418.         /* if one of frames 0-3, save the address */
  419.         if (framebuf[loop].frameno < 4)
  420.         {
  421.             frameptr[framebuf[loop].frameno] = (unsigned char far *)
  422.                                               MK_FP(framebuf[loop].segaddr, 0);
  423.         }
  424.     }
  425.     printf("Info returned checks out OK.\n");
  426.     TESTTAILER();
  427.  
  428.     /* now test EMMgetsinfraddr() */
  429.     TESTHEADER();
  430.     printf("Testing EMMgetsinfraddr() against data from EMMgetframeaddr().\n");
  431.     printf("Should succeed.\n");
  432.     /* loop through framebuf, calling EMMgetsinfraddr() on each */
  433.     for (loop = 0; loop < frames; loop++)
  434.     {
  435.         segaddr = EMMgetsinfraddr(framebuf[loop].frameno);
  436.         weirdcodechk("EMMgetsinfraddr()", 0, framebuf, 0, 0);
  437.         if (segaddr != framebuf[loop].segaddr)
  438.         {
  439.             printf("EMMgetsinfraddr(%u) succeeded but returned %u, not %u.\n",
  440.                       framebuf[loop].frameno, segaddr, framebuf[loop].segaddr);
  441.             free(framebuf);
  442.             exit(3);
  443.         }
  444.     }
  445.     printf("EMMgetsinfraddr() returned all addresses OK.\n");
  446.     TESTTAILER();
  447.  
  448.     /* clean up */
  449.     free(framebuf);
  450.     gblmsg = "";
  451.  
  452.     return;
  453. } /* end of do_frame_tests() */
  454.  
  455.  
  456. /*
  457. ** The following section of code is included only in the first tiny-model
  458. ** executable and in non-tiny-model executables.
  459. */
  460. #ifndef TINYPASS2
  461. #ifndef TINYPASS3
  462.  
  463.  
  464. /***************************************************************************
  465. *   FUNCTION: DO_ALLOC_TESTS                                               *
  466. *                                                                          *
  467. *   DESCRIPTION:                                                           *
  468. *                                                                          *
  469. *       This function tests EMSIF calls EMMcoreleft(), EMMalloc(), and     *
  470. *       EMMfree().                                                         *
  471. *                                                                          *
  472. *   ENTRY:                                                                 *
  473. *                                                                          *
  474. *       bytes - number of bytes of EMS to try to allocate.                 *
  475. *                                                                          *
  476. *   EXIT:                                                                  *
  477. *                                                                          *
  478. *       Void.                                                              *
  479. *                                                                          *
  480. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  481. *                                                                          *
  482. ***************************************************************************/
  483. void do_alloc_tests(unsigned long bytes)
  484. {
  485.     unsigned long emsfree, emsfree2;
  486.     unsigned long pagelen;
  487.     int handle;
  488.  
  489.     /* set header */
  490.     gblmsg = "  ALLOCATION TESTS";
  491.  
  492.     /* get bytes value rounded up to nearest page, or 1 page if bytes == 0 */
  493.     if (bytes != 0L)
  494.     {
  495.         pagelen = bytes + 16383L;
  496.         pagelen &= 0xFFFFC000L;
  497.     }
  498.     else
  499.     {
  500.         pagelen = 16384L;
  501.     }
  502.  
  503.     /* test coreleft */
  504.     TESTHEADER();
  505.     printf("Testing EMMcoreleft().\n");
  506.     printf("Result should be multiple of 16384.\n");
  507.     emsfree = test_EMMcoreleft();
  508.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  509.                                                   emsfree, (emsfree / 16384L));
  510.     TESTTAILER();
  511.  
  512.     /* make sure enough free */
  513.     if (emsfree < (MINFREE * 16384L))
  514.     {
  515.         printf("Insufficient free EMS to perform all tests. Aborting.\n");
  516.         exit(1);
  517.     }
  518.  
  519.     /* test allocation */
  520.     TESTHEADER();
  521.     printf("Testing EMMalloc(%lu).\n", bytes);
  522.     printf("Should succeed. Free EMS should drop by %lu bytes (%lu pages).\n",
  523.                                                   pagelen, (pagelen / 16384L));
  524.     handle = test_EMMalloc(bytes);
  525.     printf("EMMalloc() returned OK.\n");
  526.     emsfree2 = test_EMMcoreleft();
  527.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  528.                                                 emsfree2, (emsfree2 / 16384L));
  529.     if ((emsfree - emsfree2) != pagelen)
  530.     {
  531.         printf("EMMalloc(%lu) caused free to drop weirdly from %lu to %lu.\n",
  532.                                                      bytes, emsfree, emsfree2);
  533.         EMMfree(handle);
  534.         exit(3);
  535.     }
  536.     TESTTAILER();
  537.  
  538.     /* test free */
  539.     TESTHEADER();
  540.     printf("Testing EMMfree() on handle just returned by EMMalloc().\n");
  541.     printf(
  542.         "Should succeed. Free EMS should increase by %lu bytes (%lu pages).\n",
  543.         pagelen, (pagelen / 16384L));
  544.     test_EMMfree(handle);
  545.     printf("EMMfree() returned OK.\n");
  546.     emsfree2 = test_EMMcoreleft();
  547.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  548.                                                 emsfree2, (emsfree2 / 16384L));
  549.     if (emsfree2 != emsfree)
  550.     {
  551.         printf("Freeing handle returned by EMMalloc() did not restore\n");
  552.         printf("   free EMS count -- was %lu originally, now %lu.\n", emsfree,
  553.                                                                      emsfree2);
  554.         exit(3);
  555.     }
  556.     TESTTAILER();
  557.  
  558.     gblmsg = "";
  559.  
  560.     return;
  561. } /* end of do_alloc_tests() */
  562.  
  563.  
  564. /***************************************************************************
  565. *   FUNCTION: DO_PALLOC_TESTS                                              *
  566. *                                                                          *
  567. *   DESCRIPTION:                                                           *
  568. *                                                                          *
  569. *       This function tests EMSIF calls EMMcoreleft(), EMMallocpages(),    *
  570. *       and EMMfree().                                                     *
  571. *                                                                          *
  572. *   ENTRY:                                                                 *
  573. *                                                                          *
  574. *       pages - number of pages of EMS to try to allocate.                 *
  575. *                                                                          *
  576. *   EXIT:                                                                  *
  577. *                                                                          *
  578. *       Void.                                                              *
  579. *                                                                          *
  580. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  581. *                                                                          *
  582. ***************************************************************************/
  583. void do_palloc_tests(int pages)
  584. {
  585.     unsigned long emsfree, emsfree2;
  586.     unsigned long pagelen;
  587.     int handle;
  588.  
  589.     /* set header */
  590.     gblmsg = "  PAGE ALLOCATION TESTS";
  591.  
  592.     /* convert pages to bytes */
  593.     pagelen = 16384L * pages;
  594.  
  595.     /* test coreleft */
  596.     TESTHEADER();
  597.     printf("Testing EMMcoreleft().\n");
  598.     printf("Result should be multiple of 16384.\n");
  599.     emsfree = test_EMMcoreleft();
  600.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  601.                                                   emsfree, (emsfree / 16384L));
  602.     TESTTAILER();
  603.  
  604.     /* make sure enough free */
  605.     if (emsfree < (MINFREE * 16384L))
  606.     {
  607.         printf("Insufficient free EMS to perform all tests. Aborting.\n");
  608.         exit(1);
  609.     }
  610.  
  611.     /* test allocation */
  612.     TESTHEADER();
  613.     printf("Testing EMMallocpages(%d).\n", pages);
  614.     printf("Should succeed. Free EMS should drop by %lu bytes (%lu pages).\n",
  615.                                                   pagelen, (pagelen / 16384L));
  616.     handle = test_EMMallocpages(pages);
  617.     printf("EMMallocpages() retured OK.\n");
  618.     emsfree2 = test_EMMcoreleft();
  619.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  620.                                                 emsfree2, (emsfree2 / 16384L));
  621.     if ((emsfree - emsfree2) != pagelen)
  622.     {
  623.         printf(
  624.             "EMMallocpages(%d) caused free to drop weirdly from %lu to %lu.\n",
  625.             pages, emsfree, emsfree2);
  626.         EMMfree(handle);
  627.         exit(3);
  628.     }
  629.     TESTTAILER();
  630.  
  631.     /* test free */
  632.     TESTHEADER();
  633.     printf("Testing EMMfree() on handle just returned by EMMallocpages().\n");
  634.     printf(
  635.         "Should succeed. Free EMS should increase by %lu bytes (%lu pages).\n",
  636.         pagelen, (pagelen / 16384L));
  637.     test_EMMfree(handle);
  638.     printf("EMMfree() returned OK.\n");
  639.     emsfree2 = test_EMMcoreleft();
  640.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  641.                                                 emsfree2, (emsfree2 / 16384L));
  642.     if (emsfree2 != emsfree)
  643.     {
  644.         printf("Freeing handle returned by EMMallocpages() did not restore\n");
  645.         printf("   free EMS count -- was %lu originally, now %lu.\n", emsfree,
  646.                                                                      emsfree2);
  647.         exit(3);
  648.     }
  649.     TESTTAILER();
  650.  
  651.     gblmsg = "";
  652.  
  653.     return;
  654. } /* end of do_palloc_tests() */
  655.  
  656.  
  657. /***************************************************************************
  658. *   FUNCTION: DO_NAME_TESTS                                                *
  659. *                                                                          *
  660. *   DESCRIPTION:                                                           *
  661. *                                                                          *
  662. *       This function tests EMSIF calls EMMgetname() and EMMsetname().     *
  663. *                                                                          *
  664. *   ENTRY:                                                                 *
  665. *                                                                          *
  666. *       Void.                                                              *
  667. *                                                                          *
  668. *   EXIT:                                                                  *
  669. *                                                                          *
  670. *       Void.                                                              *
  671. *                                                                          *
  672. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  673. *                                                                          *
  674. ***************************************************************************/
  675. void do_name_tests(void)
  676. {
  677.     char name[9];
  678.     int handle, status;
  679.  
  680.     /* set header */
  681.     gblmsg = "  NAME TESTS";
  682.  
  683.     TESTHEADER();
  684.     printf("Testing EMMsetname() and EMMgetname().\n");
  685.     if (_EMMversion < 0x40)
  686.     {
  687.         printf(
  688.               "EMMsetname() should fail, EMMgetname() return empty buffer.\n");
  689.     }
  690.     else
  691.     {
  692.         printf("Should succeed.\n");
  693.     }
  694.     /* allocate some EMS to assign a name to */
  695.     handle = test_EMMalloc(16384);
  696.     printf("Calling EMMsetname() with name ABCDEFGH.\n");
  697.     status = EMMsetname(handle, "ABCDEFGH");
  698.     if (_EMMversion < 0x40)
  699.     {
  700.         nofailcheck("EMMsetname()", status, NULL, handle, 0);
  701.         weirdretchk("EMMsetname()", status, NULL, handle, 0);
  702.         weirdcodechk("EMMsetname()", EMM_BADVERS, NULL, handle, 0);
  703.         printf("EMMsetname() failed OK.\n");
  704.     }
  705.     else
  706.     {
  707.         TRIPLECHECK("EMMsetname()", status, 0, NULL, handle, 0);
  708.         printf("EMMsetname() succeeded.\n");
  709.     }
  710.     printf("Now calling EMMgetname().\n");
  711.     status = EMMgetname(handle, name);
  712.     TRIPLECHECK("EMMgetname()", status, 0, NULL, handle, 0);
  713.     if (_EMMversion < 0x40)
  714.     {
  715.         if (farmemcheck((unsigned char far *) name, 9, '\0') != 0)
  716.         {
  717.             printf("A character in name is not null.\n");
  718.             EMMfree(handle);
  719.             exit(3);
  720.         }
  721.     }
  722.     else
  723.     {
  724.         if (strcmp(name, "ABCDEFGH") != 0)
  725.         {
  726.             printf("Got name %s back.\n", name);
  727.             EMMfree(handle);
  728.             exit(3);
  729.         }
  730.     }
  731.     printf("EMMgetname() succeeded.\n");
  732.     test_EMMfree(handle);
  733.     TESTTAILER();
  734.  
  735.     gblmsg = "";
  736.  
  737.     return;
  738. } /* end of do_name_tests() */
  739.  
  740.  
  741. /***************************************************************************
  742. *   FUNCTION: DO_MAP_TESTS                                                 *
  743. *                                                                          *
  744. *   DESCRIPTION:                                                           *
  745. *                                                                          *
  746. *       This function tests EMSIF call EMMmappage().                       *
  747. *                                                                          *
  748. *   ENTRY:                                                                 *
  749. *                                                                          *
  750. *       Void.                                                              *
  751. *                                                                          *
  752. *   EXIT:                                                                  *
  753. *                                                                          *
  754. *       Void.                                                              *
  755. *                                                                          *
  756. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  757. *                                                                          *
  758. ***************************************************************************/
  759. void do_map_tests(void)
  760. {
  761.     int handle1, handle2;
  762.     int loop;
  763.     int status;
  764.  
  765.     /* set header */
  766.     gblmsg = "  MAPPING TESTS";
  767.  
  768.     /* first, allocate some EMS to map */
  769.     handle1 = test_EMMallocpages(6);
  770.     handle2 = test_EMMallocpages(2);
  771.  
  772.     /* initial test of EMMmappage() */
  773.     TESTHEADER();
  774.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 0).\n");
  775.     printf("Should succeed.\n");
  776.     test_EMMmappage(0, handle1, 0);
  777.     printf("EMMmappage() returned OK.\n");
  778.     TESTTAILER();
  779.  
  780.     /* calling EMMmappage() with a bad logical page number */
  781.     TESTHEADER();
  782.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 6).\n");
  783.     printf("Should fail.\n");
  784.     status = EMMmappage(0, handle1, 6);
  785.     nofailcheck("EMMmappage()", status, NULL, handle1, handle2);
  786.     weirdretchk("EMMmappage()", status, NULL, handle1, handle2);
  787.     weirdcodechk("EMMmappage()", EMM_BADLOGPAGE, NULL, handle1, handle2);
  788.     printf("EMMmappage() failed OK.\n");
  789.     TESTTAILER();
  790.  
  791.     TESTHEADER();
  792.     printf("Writing data pattern to page 0, first handle... ");
  793.     FMEMSET(frameptr[0], 0, 16384);
  794.     printf("Verifying... ");
  795.     if (farmemcheck(frameptr[0], 16384, 0) != 0)
  796.     {
  797.         printf("Verify failed!\n");
  798.         test_EMMfree(handle1);
  799.         test_EMMfree(handle2);
  800.         exit(3);
  801.     }
  802.     printf("OK.\n");
  803.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 1).\n");
  804.     test_EMMmappage(0, handle1, 1);
  805.     printf("EMMmappage() returned OK.\n");
  806.     printf("Writing data pattern to page 1, first handle... ");
  807.     FMEMSET(frameptr[0], 1, 16384);
  808.     printf("Verifying... ");
  809.     if (farmemcheck(frameptr[0], 16384, 1) != 0)
  810.     {
  811.         printf("Verify failed!\n");
  812.         test_EMMfree(handle1);
  813.         test_EMMfree(handle2);
  814.         exit(3);
  815.     }
  816.     printf("OK.\n");
  817.     printf("Now mapping page 0 back, see if it's still OK.\n");
  818.     test_EMMmappage(0, handle1, 0);
  819.     printf("EMMmappage() returned OK, verifying contents... ");
  820.     if (farmemcheck(frameptr[0], 16384, 0) != 0)
  821.     {
  822.         printf("Verify failed!\n");
  823.         test_EMMfree(handle1);
  824.         test_EMMfree(handle2);
  825.         exit(3);
  826.     }
  827.     printf("OK.\n");
  828.     printf("EMMmappage() looks like it's doing something.\n");
  829.     TESTTAILER();
  830.  
  831.     TESTHEADER();
  832.     printf("Testing mapping of all frames...\n");
  833.     printf("Filling rest of allocated pages with unique patterns... ");
  834.     for (loop = 2; loop < 6; loop++)
  835.     {
  836.         test_EMMmappage(0, handle1, loop);
  837.         FMEMSET(frameptr[0], loop, 16384);
  838.         if (farmemcheck(frameptr[0], 16384, (unsigned char) loop) != 0)
  839.         {
  840.             printf("Verify failed on handle 1, page %d.\n", loop);
  841.             test_EMMfree(handle1);
  842.             test_EMMfree(handle2);
  843.             exit(3);
  844.         }
  845.     }
  846.     test_EMMmappage(0, handle2, 0);
  847.     FMEMSET(frameptr[0], 0x10, 16384);
  848.     if (farmemcheck(frameptr[0], 16384, 0x10) != 0)
  849.     {
  850.         printf("Verify failed on handle 2, page 0!\n");
  851.         test_EMMfree(handle1);
  852.         test_EMMfree(handle2);
  853.         exit(3);
  854.     }
  855.     test_EMMmappage(0, handle2, 1);
  856.     FMEMSET(frameptr[0], 0x11, 16384);
  857.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  858.     {
  859.         printf("Verify failed on handle 2, page 1!\n");
  860.         test_EMMfree(handle1);
  861.         test_EMMfree(handle2);
  862.         exit(3);
  863.     }
  864.     printf("Done.\n");
  865.     printf("Mapping handle 1 pages 0-3 in frames 0-3 respectively... ");
  866.     for (loop = 0; loop < 4; loop++)
  867.     {
  868.         test_EMMmappage(loop, handle1, loop);
  869.     }
  870.     printf("Done.\n");
  871.     printf("Verifying contents... ");
  872.     for (loop = 0; loop < 4; loop++)
  873.     {
  874.         if (farmemcheck(frameptr[loop], 16384, (unsigned char) loop) != 0)
  875.         {
  876.             printf("Verify failed for frame %d.\n", loop);
  877.             test_EMMfree(handle1);
  878.             test_EMMfree(handle2);
  879.             exit(3);
  880.         }
  881.     }
  882.     printf("OK.\n");
  883.     printf("Mapping handle 1 pages 0-3 in frames 0-3 in reverse... ");
  884.     for (loop = 0; loop < 4; loop++)
  885.     {
  886.         test_EMMmappage(loop, handle1, (3 - loop));
  887.     }
  888.     printf("Done.\n");
  889.     printf("Verifying contents... ");
  890.     for (loop = 0; loop < 4; loop++)
  891.     {
  892.         if (farmemcheck(frameptr[loop], 16384, (unsigned char)(3 - loop)) != 0)
  893.         {
  894.             printf("Verify failed for frame %d.\n", loop);
  895.             test_EMMfree(handle1);
  896.             test_EMMfree(handle2);
  897.             exit(3);
  898.         }
  899.     }
  900.     printf("OK.\n");
  901.     printf(
  902.       "Mapping handle 1 pages 0-3 in frames 0-3 except page 5 in frame 2... ");
  903.     for (loop = 0; loop < 4; loop++)
  904.     {
  905.         test_EMMmappage(loop, handle1, loop);
  906.     }
  907.     test_EMMmappage(2, handle1, 5);
  908.     printf("Done.\n");
  909.     printf("Verifying contents... ");
  910.     for (loop = 0; loop < 4; loop++)
  911.     {
  912.         if (farmemcheck(frameptr[loop], 16384,
  913.                                  (unsigned char)((loop != 2) ? loop : 5)) != 0)
  914.         {
  915.             printf("Verify failed for frame %d.\n", loop);
  916.             test_EMMfree(handle1);
  917.             test_EMMfree(handle2);
  918.             exit(3);
  919.         }
  920.     }
  921.     printf("OK.\n");
  922.     TESTTAILER();
  923.  
  924.     TESTHEADER();
  925.     printf("Final mapping test... two handles at once!\n");
  926.     printf("Mapping handle2 page 1 in frame 0.\n");
  927.     printf("        handle1 page 4 in frame 1.\n");
  928.     printf("        handle1 page 0 in frame 2.\n");
  929.     printf("        handle2 page 0 in frame 3.\n");
  930.     test_EMMmappage(0, handle2, 1);
  931.     test_EMMmappage(1, handle1, 4);
  932.     test_EMMmappage(2, handle1, 0);
  933.     test_EMMmappage(3, handle2, 0);
  934.     printf("Mapping done. Verifying... ");
  935.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  936.     {
  937.         printf("Verify failed for frame 0.\n");
  938.         test_EMMfree(handle1);
  939.         test_EMMfree(handle2);
  940.         exit(3);
  941.     }
  942.     if (farmemcheck(frameptr[1], 16384, 4) != 0)
  943.     {
  944.         printf("Verify failed for frame 1.\n");
  945.         test_EMMfree(handle1);
  946.         test_EMMfree(handle2);
  947.         exit(3);
  948.     }
  949.     if (farmemcheck(frameptr[2], 16384, 0) != 0)
  950.     {
  951.         printf("Verify failed for frame 2.\n");
  952.         test_EMMfree(handle1);
  953.         test_EMMfree(handle2);
  954.         exit(3);
  955.     }
  956.     if (farmemcheck(frameptr[3], 16384, 0x10) != 0)
  957.     {
  958.         printf("Verify failed for frame 3.\n");
  959.         test_EMMfree(handle1);
  960.         test_EMMfree(handle2);
  961.         exit(3);
  962.     }
  963.     printf("OK.\n");
  964.     TESTTAILER();
  965.  
  966.     /* clean up */
  967.     test_EMMfree(handle1);
  968.     test_EMMfree(handle2);
  969.     gblmsg = "";
  970.  
  971.     return;
  972. } /* end of do_map_tests() */
  973.  
  974.  
  975. /***************************************************************************
  976. *   FUNCTION: DO_SR_TESTS                                                  *
  977. *                                                                          *
  978. *   DESCRIPTION:                                                           *
  979. *                                                                          *
  980. *       This function tests the EMSIF mapping save/restore functions:      *
  981. *       EMMsrinit(), EMMsave(), EMMrestore().                              *
  982. *                                                                          *
  983. *   ENTRY:                                                                 *
  984. *                                                                          *
  985. *       Void.                                                              *
  986. *                                                                          *
  987. *   EXIT:                                                                  *
  988. *                                                                          *
  989. *       Void.                                                              *
  990. *                                                                          *
  991. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  992. *                                                                          *
  993. ***************************************************************************/
  994. void do_sr_tests(void)
  995. {
  996.     void *savehandle;
  997.     int handle1, handle2;
  998.     int status;
  999.     int loop;
  1000.  
  1001.     /* set header */
  1002.     gblmsg = "  SAVE/RESTORE TESTS";
  1003.  
  1004.     /* first, allocate some EMS and fill with unique patterns */
  1005.     handle1 = test_EMMallocpages(6);
  1006.     handle2 = test_EMMallocpages(2);
  1007.     for (loop = 0; loop < 6; loop++)
  1008.     {
  1009.         test_EMMmappage(0, handle1, loop);
  1010.         FMEMSET(frameptr[0], loop, 16384);
  1011.         if (farmemcheck(frameptr[0], 16384, (unsigned char) loop) != 0)
  1012.         {
  1013.             printf("Verify failed on handle 1, page %d.\n", loop);
  1014.             test_EMMfree(handle1);
  1015.             test_EMMfree(handle2);
  1016.             exit(3);
  1017.         }
  1018.     }
  1019.     test_EMMmappage(0, handle2, 0);
  1020.     FMEMSET(frameptr[0], 0x10, 16384);
  1021.     if (farmemcheck(frameptr[0], 16384, 0x10) != 0)
  1022.     {
  1023.         printf("Verify failed on handle 2, page 0!\n");
  1024.         test_EMMfree(handle1);
  1025.         test_EMMfree(handle2);
  1026.         exit(3);
  1027.     }
  1028.     test_EMMmappage(0, handle2, 1);
  1029.     FMEMSET(frameptr[0], 0x11, 16384);
  1030.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  1031.     {
  1032.         printf("Verify failed on handle 2, page 1!\n");
  1033.         test_EMMfree(handle1);
  1034.         test_EMMfree(handle2);
  1035.         exit(3);
  1036.     }
  1037.  
  1038.     TESTHEADER();
  1039.     printf(
  1040.      "Testing save/restore facility. Calling EMMsave() before EMMsrinit().\n");
  1041.     printf("Should fail.\n");
  1042.     savehandle = EMMsave();
  1043.     nofailcheck("EMMsave()", (int) _EMMerror, NULL, handle1, handle2);
  1044.     weirdcodechk("EMMsave()", EMM_NOSR, NULL, handle1, handle2);
  1045.     printf("EMMsave() failed OK.\n");
  1046.     TESTTAILER();
  1047.  
  1048.     TESTHEADER();
  1049.     printf("Calling EMMsrinit().\nShould %s.\n",
  1050.                                  ((_EMMversion >= 0x32) ? "succeed" : "fail"));
  1051.     status = EMMsrinit(malloc);
  1052.     if (_EMMversion >= 0x32)
  1053.     {
  1054.         TRIPLECHECK("EMMsrinit()", status, 0, NULL, handle1, handle2);
  1055.         printf("EMMsrinit() succeeded; save/restore facility initialized.\n");
  1056.     }
  1057.     else
  1058.     {
  1059.         weirdretchk("EMMsrinit()", status, NULL, handle1, handle2);
  1060.         nofailcheck("EMMsrinit()", status, NULL, handle1, handle2);
  1061.         weirdcodechk("EMMsrinit()", EMM_BADVERS, NULL, handle1, handle2);
  1062.         printf("EMMsrinit() failed OK. Skipping other save/restore tests.\n");
  1063.     }
  1064.     TESTTAILER();
  1065.  
  1066.     if (_EMMversion >= 0x32)
  1067.     {
  1068.         TESTHEADER();
  1069.         printf("Testing EMMsave().\n");
  1070.         printf("Mapping handle 1 pages 0-3 in frames 0-3 respectively.\n");
  1071.         for (loop = 0; loop < 4; loop++)
  1072.         {
  1073.             test_EMMmappage(loop, handle1, loop);
  1074.         }
  1075.  
  1076.         printf("Calling EMMsave() to save current configuration.\n");
  1077.         printf("Should succeed.\n");
  1078.         savehandle = (void *) NULL;
  1079.         savehandle = EMMsave();
  1080.         if (savehandle == (void *) NULL)
  1081.         {
  1082.             printf("EMMsave() did not return anything, code 0x%X.\n",
  1083.                                                      (unsigned int) _EMMerror);
  1084.             test_EMMfree(handle1);
  1085.             test_EMMfree(handle2);
  1086.             exit(3);
  1087.         }
  1088.         weirdcodechk("EMMsave()", 0, NULL, handle1, handle2);
  1089.         printf("EMMsave() succeeded.\n");
  1090.         TESTTAILER();
  1091.  
  1092.         printf("Changing configuration.\n");
  1093.         test_EMMmappage(0, handle2, 1);
  1094.         test_EMMmappage(1, handle1, 4);
  1095.         test_EMMmappage(2, handle1, 0);
  1096.         test_EMMmappage(3, handle2, 0);
  1097.  
  1098.         TESTHEADER();
  1099.         printf("Calling EMMrestore() to restore previous configuration.\n");
  1100.         printf("Should succeed.\n");
  1101.         status = EMMrestore(savehandle);
  1102.         TRIPLECHECK("EMMrestore()", status, 0, NULL, handle1, handle2);
  1103.         printf("EMMrestore() returned OK, verifying contents... ");
  1104.         for (loop = 0; loop < 4; loop++)
  1105.         {
  1106.             if (farmemcheck(frameptr[loop], 16384, (unsigned char) loop) != 0)
  1107.             {
  1108.                 printf("Verify failed for frame %d.\n", loop);
  1109.                 test_EMMfree(handle1);
  1110.                 test_EMMfree(handle2);
  1111.                 exit(3);
  1112.             }
  1113.         }
  1114.         printf("OK.\n");
  1115.         TESTTAILER();
  1116.     }
  1117.  
  1118.     printf("Cleaning up.\n");
  1119.     test_EMMfree(handle1);
  1120.     test_EMMfree(handle2);
  1121.     if (_EMMversion >= 0x32)
  1122.     {
  1123.         free(savehandle);
  1124.     }
  1125.     gblmsg = "";
  1126.  
  1127.     return;
  1128. } /* end of do_sr_tests() */
  1129.  
  1130. #endif
  1131. #endif
  1132.  
  1133.  
  1134. /*
  1135. ** The following group of functions {test_EMM*()} are wrapper functions
  1136. ** that call the EMSIF function named and perform preliminary checks on
  1137. ** the return values. This keeps code size down since the check only has
  1138. ** to be coded in one place.
  1139. */
  1140.  
  1141. /***************************************************************************
  1142. *   FUNCTION: TEST_EMMCORELEFT                                             *
  1143. *                                                                          *
  1144. *   DESCRIPTION:                                                           *
  1145. *                                                                          *
  1146. *       This function calls EMSIF function EMMcoreleft() and checks the    *
  1147. *       return value to see if it is a multiple of 16384 (the EMS page     *
  1148. *       size).                                                             *
  1149. *                                                                          *
  1150. *   ENTRY:                                                                 *
  1151. *                                                                          *
  1152. *       Void.                                                              *
  1153. *                                                                          *
  1154. *   EXIT:                                                                  *
  1155. *                                                                          *
  1156. *       Returns the value returned by EMMcoreleft().                       *
  1157. *                                                                          *
  1158. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1159. *                                                                          *
  1160. ***************************************************************************/
  1161. unsigned long test_EMMcoreleft(void)
  1162. {
  1163.     unsigned long emsfree;
  1164.  
  1165.     /* call EMMcoreleft and check error code */
  1166.     emsfree = EMMcoreleft();
  1167.     weirdcodechk("EMMcoreleft()", 0, NULL, 0, 0);
  1168.  
  1169.     /* check if free byte count is multiple of 16384 */
  1170.     if ((emsfree % 16384L) != 0)
  1171.     {
  1172.         printf("EMMcoreleft() returned strange number %lu.\n", emsfree);
  1173.         exit(3);
  1174.     }
  1175.  
  1176.     return emsfree;
  1177. } /* end of test_EMMcoreleft() */
  1178.  
  1179.  
  1180. /***************************************************************************
  1181. *   FUNCTION: TEST_EMMALLOC                                                *
  1182. *                                                                          *
  1183. *   DESCRIPTION:                                                           *
  1184. *                                                                          *
  1185. *       This function calls EMSIF function EMMalloc() and checks the       *
  1186. *       return codes.                                                      *
  1187. *                                                                          *
  1188. *   ENTRY:                                                                 *
  1189. *                                                                          *
  1190. *       bytes - bytes of EMS to allocate                                   *
  1191. *                                                                          *
  1192. *   EXIT:                                                                  *
  1193. *                                                                          *
  1194. *       Returns the handle returned by EMMalloc().                         *
  1195. *                                                                          *
  1196. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1197. *                                                                          *
  1198. ***************************************************************************/
  1199. int test_EMMalloc(unsigned long bytes)
  1200. {
  1201.     int handle;
  1202.  
  1203.     /* call EMMalloc() and check the return */
  1204.     handle = EMMalloc(bytes);
  1205.     weirdcodechk("EMMalloc()", 0, NULL, 0, 0);
  1206.  
  1207.     return handle;
  1208. } /* end of test_EMMalloc() */
  1209.  
  1210.  
  1211. /***************************************************************************
  1212. *   FUNCTION: TEST_EMMALLOCPAGES                                           *
  1213. *                                                                          *
  1214. *   DESCRIPTION:                                                           *
  1215. *                                                                          *
  1216. *       This function calls EMSIF function EMMallocpages() and checks the  *
  1217. *       return codes.                                                      *
  1218. *                                                                          *
  1219. *   ENTRY:                                                                 *
  1220. *                                                                          *
  1221. *       pages - pages of EMS to allocate                                   *
  1222. *                                                                          *
  1223. *   EXIT:                                                                  *
  1224. *                                                                          *
  1225. *       Returns the handle returned by EMMallocpages().                    *
  1226. *                                                                          *
  1227. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1228. *                                                                          *
  1229. ***************************************************************************/
  1230. int test_EMMallocpages(int pages)
  1231. {
  1232.     int handle;
  1233.  
  1234.     /* call EMMallocpages() and check the return */
  1235.     handle = EMMallocpages(pages);
  1236.     weirdcodechk("EMMallocpages()", 0, NULL, 0, 0);
  1237.  
  1238.     return handle;
  1239. } /* end of test_EMMallocpages() */
  1240.  
  1241.  
  1242. /***************************************************************************
  1243. *   FUNCTION: TEST_EMMFREE                                                 *
  1244. *                                                                          *
  1245. *   DESCRIPTION:                                                           *
  1246. *                                                                          *
  1247. *       This function calls EMSIF function EMMfree() and checks the        *
  1248. *       return codes.                                                      *
  1249. *                                                                          *
  1250. *   ENTRY:                                                                 *
  1251. *                                                                          *
  1252. *       handle - EMS handle to be freed                                    *
  1253. *                                                                          *
  1254. *   EXIT:                                                                  *
  1255. *                                                                          *
  1256. *       Void.                                                              *
  1257. *                                                                          *
  1258. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1259. *                                                                          *
  1260. ***************************************************************************/
  1261. void test_EMMfree(int handle)
  1262. {
  1263.     int status;
  1264.  
  1265.     /* call EMMfree() and check the return */
  1266.     status = EMMfree(handle);
  1267.     TRIPLECHECK("EMMfree()", status, 0, NULL, 0, 0);
  1268.  
  1269.     return;
  1270. } /* end of test_EMMfree() */
  1271.  
  1272.  
  1273. /***************************************************************************
  1274. *   FUNCTION: TEST_EMMMAPPAGE                                              *
  1275. *                                                                          *
  1276. *   DESCRIPTION:                                                           *
  1277. *                                                                          *
  1278. *       This function calls EMSIF function EMMmappage() and checks the     *
  1279. *       return codes.                                                      *
  1280. *                                                                          *
  1281. *   ENTRY:                                                                 *
  1282. *                                                                          *
  1283. *       frameno - frame number to map page into                            *
  1284. *       handle  - handle of page to be mapped                              *
  1285. *       logpage - page number to map                                       *
  1286. *                                                                          *
  1287. *   EXIT:                                                                  *
  1288. *                                                                          *
  1289. *       Void.                                                              *
  1290. *                                                                          *
  1291. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1292. *                                                                          *
  1293. ***************************************************************************/
  1294. void test_EMMmappage(int frameno, int handle, int logpage)
  1295. {
  1296.     int status;
  1297.  
  1298.     /*
  1299.     ** do sanity check on frame number, just in case -- we shouldn't be
  1300.     ** trying to map into frames other than standard 0 through 3.
  1301.     */
  1302.     if ((frameno < 0) || (frameno > 3))
  1303.     {
  1304.         printf("Sanity check failed, trying to map to frame %d, aborting.\n",
  1305.                                                                       frameno);
  1306.         EMMfree(handle);
  1307.         exit(3);
  1308.     }
  1309.  
  1310.     /* call EMMmappage() and check return */
  1311.     status = EMMmappage(frameno, handle, logpage);
  1312.     TRIPLECHECK("EMMmappage()", status, 0, NULL, handle, 0);
  1313.  
  1314.     return;
  1315. } /* end of test_EMMmappage() */
  1316.  
  1317.  
  1318. /*
  1319. ** The following group of functions are used to speed up return checking
  1320. ** and keep code size down, since the return check only has to be coded
  1321. ** in one place. They are used in various macros to further compact and
  1322. ** clarify the code.
  1323. */
  1324.  
  1325. /***************************************************************************
  1326. *   FUNCTION: WEIRDRETCHK                                                  *
  1327. *                                                                          *
  1328. *   DESCRIPTION:                                                           *
  1329. *                                                                          *
  1330. *       This function checks to see if the status value passed to it is    *
  1331. *       either 0 or EMMOOPS, and assumes something has gone wrong if it    *
  1332. *       is not. If something has gone wrong, does some clean up before     *
  1333. *       exiting.                                                           *
  1334. *                                                                          *
  1335. *   ENTRY:                                                                 *
  1336. *                                                                          *
  1337. *       function - name of function which may have goofed                  *
  1338. *       status   - status value to check                                   *
  1339. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1340. *                  freed if NULL.                                          *
  1341. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1342. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1343. *                                                                          *
  1344. *   EXIT:                                                                  *
  1345. *                                                                          *
  1346. *       Void, or may not return.                                           *
  1347. *                                                                          *
  1348. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1349. *                                                                          *
  1350. ***************************************************************************/
  1351. void weirdretchk(char *function, int status, void *tofree1, int tofree2,
  1352.                                                                    int tofree3)
  1353. {
  1354.     if ((status != EMMOOPS) && (status != 0))
  1355.     {
  1356.         printf("%s returned weird value %d, code 0x%X.\n", function, status,
  1357.                                                      (unsigned int) _EMMerror);
  1358.         if (tofree1 != (void *) NULL)
  1359.         {
  1360.             free(tofree1);
  1361.         }
  1362.         if (tofree2 != 0)
  1363.         {
  1364.             EMMfree(tofree2);
  1365.         }
  1366.         if (tofree3 != 0)
  1367.         {
  1368.             EMMfree(tofree3);
  1369.         }
  1370.         exit(3);
  1371.     }
  1372.  
  1373.     return;
  1374. } /* end of weirdretchk() */
  1375.  
  1376.  
  1377. /***************************************************************************
  1378. *   FUNCTION: WEIRDCODECHK                                                 *
  1379. *                                                                          *
  1380. *   DESCRIPTION:                                                           *
  1381. *                                                                          *
  1382. *       This function checks to see if the EMSIF error code value matches  *
  1383. *       the expected value, and assumes something has gone wrong if it     *
  1384. *       does not. If something has gone wrong, does some clean up before   *
  1385. *       exiting.                                                           *
  1386. *                                                                          *
  1387. *   ENTRY:                                                                 *
  1388. *                                                                          *
  1389. *       function - name of function which may have goofed                  *
  1390. *       expected - expected value of _EMMerror                             *
  1391. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1392. *                  freed if NULL.                                          *
  1393. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1394. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1395. *                                                                          *
  1396. *   EXIT:                                                                  *
  1397. *                                                                          *
  1398. *       Void, or may not return.                                           *
  1399. *                                                                          *
  1400. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1401. *                                                                          *
  1402. ***************************************************************************/
  1403. void weirdcodechk(char *function, int expected, void *tofree1, int tofree2,
  1404.                                                                    int tofree3)
  1405. {
  1406.     if ((int) _EMMerror != expected)
  1407.     {
  1408.         printf("%s returned unexpected code 0x%X.\n", function,
  1409.                                                      (unsigned int) _EMMerror);
  1410.         if (tofree1 != (void *) NULL)
  1411.         {
  1412.             free(tofree1);
  1413.         }
  1414.         if (tofree2 != 0)
  1415.         {
  1416.             EMMfree(tofree2);
  1417.         }
  1418.         if (tofree3 != 0)
  1419.         {
  1420.             EMMfree(tofree3);
  1421.         }
  1422.         exit(3);
  1423.     }
  1424.  
  1425.     return;
  1426. } /* end of weirdcodechk() */
  1427.  
  1428.  
  1429. /***************************************************************************
  1430. *   FUNCTION: FAILCHECK                                                    *
  1431. *                                                                          *
  1432. *   DESCRIPTION:                                                           *
  1433. *                                                                          *
  1434. *       This function checks to see if the status value passed to it is    *
  1435. *       EMMOOPS and exits if it is. failcheck() is used when a function    *
  1436. *       is expected to succeed. Does some clean up before exiting.         *
  1437. *                                                                          *
  1438. *   ENTRY:                                                                 *
  1439. *                                                                          *
  1440. *       function - name of function which may have goofed                  *
  1441. *       status   - status value to be checked                              *
  1442. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1443. *                  freed if NULL.                                          *
  1444. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1445. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1446. *                                                                          *
  1447. *   EXIT:                                                                  *
  1448. *                                                                          *
  1449. *       Void, or may not return.                                           *
  1450. *                                                                          *
  1451. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1452. *                                                                          *
  1453. ***************************************************************************/
  1454. void failcheck(char *function, int status, void *tofree1, int tofree2,
  1455.                                                                   int tofree3)
  1456. {
  1457.     if (status == EMMOOPS)
  1458.     {
  1459.         printf("%s failed, code 0x%X.\n", function, (unsigned int) _EMMerror);
  1460.         if (tofree1 != (void *) NULL)
  1461.         {
  1462.             free(tofree1);
  1463.         }
  1464.         if (tofree2 != 0)
  1465.         {
  1466.             EMMfree(tofree2);
  1467.         }
  1468.         if (tofree3 != 0)
  1469.         {
  1470.             EMMfree(tofree3);
  1471.         }
  1472.         exit(3);
  1473.     }
  1474.  
  1475.     return;
  1476. } /* end of failcheck() */
  1477.  
  1478.  
  1479. /***************************************************************************
  1480. *   FUNCTION: NOFAILCHECK                                                  *
  1481. *                                                                          *
  1482. *   DESCRIPTION:                                                           *
  1483. *                                                                          *
  1484. *       This function checks to see if the status value passed to it is    *
  1485. *       0 and exits if it is. nofailcheck() is used when a function is     *
  1486. *       expected to fail. Does some clean up before exiting.               *
  1487. *                                                                          *
  1488. *   ENTRY:                                                                 *
  1489. *                                                                          *
  1490. *       function - name of function which may have goofed                  *
  1491. *       status   - status value to be checked                              *
  1492. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1493. *                  freed if NULL.                                          *
  1494. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1495. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1496. *                                                                          *
  1497. *   EXIT:                                                                  *
  1498. *                                                                          *
  1499. *       Void, or may not return.                                           *
  1500. *                                                                          *
  1501. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1502. *                                                                          *
  1503. ***************************************************************************/
  1504. void nofailcheck(char *function, int status, void *tofree1, int tofree2,
  1505.                                                                   int tofree3)
  1506. {
  1507.     if (status == 0)
  1508.     {
  1509.         printf("%s did not fail.\n", function);
  1510.         if (tofree1 != (void *) NULL)
  1511.         {
  1512.             free(tofree1);
  1513.         }
  1514.         if (tofree2 != 0)
  1515.         {
  1516.             EMMfree(tofree2);
  1517.         }
  1518.         if (tofree3 != 0)
  1519.         {
  1520.             EMMfree(tofree3);
  1521.         }
  1522.         exit(3);
  1523.     }
  1524.  
  1525.     return;
  1526. } /* end of nofailcheck() */
  1527.  
  1528.